﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuickJob.forms
{
    public partial class DropConfigItemCreate : Form
    {

        public event Ulitily.DropConfigItemCreateHandler onDropConfigItemCreateHandler;

        public DropConfigItemCreate()
        {
            InitializeComponent();

            textBox_config.Text = "配置" + Guid.NewGuid().ToString();
            textBox_pingMing.Text = "T恤";
            textBox_kuanMing.Text = "W0001";
            textBox_buLiao.Text = "棉65% \n  聚酯纤维35%";
            textBox_dir.Text = "C:\\Users\\Administrator\\Desktop\\模板.jpg";
            textBox_dir.DoubleClick += textBox_dir_DoubleClick;
        }

        void textBox_dir_DoubleClick(object sender, EventArgs e)
        {
            OpenFileDialog file = new OpenFileDialog();
            file.Title = "选择　洗水唛　的图片文件：xxx.jpeg  or jpg";
            if (file.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                if (file.CheckFileExists == false)
                {
                    MessageBox.Show("文件无效");
                }
                else
                {
                    this.textBox_dir.Text = file.FileName;
                }
            }
        }

        private void button_Cannel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        void Assert(ref TextBox text){

            if (text.Text == null || text.Text == "") text.Text = Guid.NewGuid().ToString();
            if (text == textBox_dir) text.Text = "C:\\Users\\Administrator\\Desktop\\模板.jpg"; 
        }


        private void button_Add_Click(object sender, EventArgs e)
        {
            Assert(ref textBox_pingMing);
            Assert(ref textBox_kuanMing);
            Assert(ref textBox_dir);
            Assert(ref textBox_buLiao);
            Assert(ref textBox_config);

            Ulitily.DropConfigItemCreateEventArgs arg = new Ulitily.DropConfigItemCreateEventArgs();
            arg.ConfigName = textBox_config.Text;
            arg.PingMing = textBox_pingMing.Text;
            arg.KuanMing = textBox_kuanMing.Text;
            arg.BuLiao = textBox_buLiao.Text;
            arg.Dir = textBox_dir.Text;
            if (onDropConfigItemCreateHandler != null) onDropConfigItemCreateHandler(this, arg);
            Close();
        }
    }
}
